import Axios from 'axios'
import qs from 'querystring'
/* 全局配置 axios */
const request = Axios.create({
  // baseURL: '',
  timeout: 50000
})
request.interceptors.request.use(
  config => {
    const token = window.sessionStorage.getItem('token')
    if (token) {
      config.headers.Token = token
    }
    // 如果post请求content-type数据类型为 application/x-www-form-urlencoded data需要转为urlencoded
    if (config.method === 'post') {
      config.data = qs.stringify(config.data)
    }
    // console.log(config)
    // 配置 urlencoded编码 的请求头
    config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    return config
  }, err => {
    console.log(err)
    return err
  })
export default request
